{# The worker's queues, re-sent over SSE when they change: totals, a card per queue read left to right (waiting, running, done, then how the backlog is trending) and each queue's share of the waiting and finished work. #} {% from "components/macros/layout.html" import stats_strip, card, badge, sparkline %} {% from "components/macros/feedback.html" import empty_state %} {% set w = worker %} {% macro shares(key, total, label) %}
{{ label }}{{ "{:,}".format(total) }}
{% for q in w.queues %}{% set share = q[key ~ "_share"] %} {% if share %}{% endif %} {% endfor %}
{% endmacro %} {# Up to 40 slots, lit in proportion to the jobs running in them: a queue's, or one process's. #} {% macro slot_row(busy, slots) %} {% set cells = [slots, 40]|min %} {% set lit = ((busy * cells / slots)|round(0, "ceil")|int) if busy and slots else 0 %}
{% for i in range(cells) %}{% endfor %}
{% endmacro %}
{{ stats_strip([ {"label": "Running", "value": w.busy ~ " / " ~ w.slots, "caption": w.busy_pct ~ "% of capacity"}, {"label": "Waiting", "value": "{:,}".format(w.queued), "caption": "across " ~ w.queues|length ~ (" queue" if w.queues|length == 1 else " queues")}, {"label": "Completed", "value": "{:,}".format(w.completed), "caption": (w.success ~ "% succeeded") if w.success is not none else "no runs yet", "tone": "ok" if w.success_color == "green" else none}, {"label": "Failed", "value": "{:,}".format(w.failed), "tone": "error" if w.failed else none}, ], id="worker-figures") }}
{% for q in w.queues %} {% set finished = q.completed + q.failed %}

{{ q.name }}

{% if q.description %}

{{ q.description }}

{% endif %}
{{ badge(q.state ~ (" · " ~ q.detail if q.detail else ""), q.tone) }}
Waiting{{ "{:,}".format(q.queued) }}
{% for i in range(40) %}{% endfor %}

{% if q.pile.per_block > 1 %}1 block ≈ {{ "{:,}".format(q.pile.per_block) }} jobs{% else %}each block is a job{% endif %}{% if q.oldest %} · oldest {{ q.oldest }}{% endif %}

Running{{ q.busy }}
{% if q.processes|length > 1 %} {# A row per process: its slots, lit by the jobs it is running. #}
{% for p in q.processes %}

{{ p.worker }} · {{ p.busy }} of {{ p.slots }}

{{ slot_row(p.busy, p.slots) }}
{% endfor %}
{% else %} {{ slot_row(q.busy, q.slots) }} {% endif %}

{{ q.busy }} of {{ q.slots }} slots taken · {{ q.busy_pct }}% of capacity

Done{{ "{:,}".format(q.completed) }}
{% if finished %}{% endif %}

{{ "{:,}".format(q.failed) }} failed{% if q.success is not none %} · {{ q.success }}%{% endif %}{% if q.rate %} · {{ q.rate }} jobs/s{% endif %}

{{ sparkline(q.spark, "h-7 w-48 shrink-0 sm:w-60") }} Waiting, last 5 min
{{ q.drain }}

{{ q.consumers }} {{ "consumer" if q.consumers == 1 else "consumers" }}{% if q.timeout %} · {{ q.timeout }}s timeout{% endif %}{% if q.stream %} · {{ q.stream }}{% endif %}

{% else %} {% if w.problem %}

{{ w.problem }}

{% else %} {{ empty_state("No queues reporting", "Queues appear here once a worker is running and has registered them.") }} {% endif %} {% endfor %}
{% if w.queues %} {% call card("Share of the work", "Each queue's part of what is waiting and of what has finished", id="worker-distribution") %}
{{ shares("backlog", w.queued, "Waiting") }} {{ shares("work", w.completed + w.failed, "Finished") }}
{% for q in w.queues %}{{ q.name }}{% endfor %}
{% endcall %} {% endif %}